//
//  DetailsController.m
//  HaoHaiSpell
//
//  Created by haohai on 16/6/15.
//  Copyright © 2016年 海城. All rights reserved.
//

#import "DetailsController.h"
#import "DetailsCell.h"
#import "DetailsCell_1.h"
#import "DetailsCell_2.h"
#import "DetailsCell_3.h"
<<<<<<< HEAD

#import "UIViewController+KNSemiModal.h"

#import "ShoppingController.h"
=======
//#import "DetailsNewCell.h"
#import "UIViewController+KNSemiModal.h"

#import "IndexModel.h"
#import "InfoModel.h"
>>>>>>> 5bee59541ff07dbcbaa6fe419e6df24b39c5e23d

@interface DetailsController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

@property (nonatomic ,strong)UICollectionView *allCollectionView;
<<<<<<< HEAD
@property (nonatomic,strong)NSMutableArray *cellArr;
=======
@property (nonatomic, strong)NSMutableArray *cellArr;
@property (nonatomic, strong)NSMutableArray *dataArray;


@property (nonatomic, strong)UILabel *titleLabel;    //标题
@property (nonatomic, strong)UILabel *priceLabel;    //价格
@property (nonatomic, strong)UILabel *promptLabel;  //提示

>>>>>>> 5bee59541ff07dbcbaa6fe419e6df24b39c5e23d

@end

@implementation DetailsController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addBottomBtn];
    [self.view addSubview:self.allCollectionView];

    self.allCollectionView.backgroundColor = [UIColor whiteColor];
    NSArray *allArr = @[@"DetailsCell",@"DetailsCell_1",@"DetailsCell_2",@"DetailsCell_3"];
        for (int i = 0; i<allArr.count;i++) {
        [self.allCollectionView registerNib:[UINib nibWithNibName:self.cellArr[i] bundle:nil] forCellWithReuseIdentifier:allArr[i]];
    }
<<<<<<< HEAD
}


//-(void)viewDidAppear:(BOOL)animated{

//    self.navigationController.navigationBarHidden = NO;
//}
=======
    
}



>>>>>>> 5bee59541ff07dbcbaa6fe419e6df24b39c5e23d

#pragma mark -- 懒加载

-(UICollectionView *)allCollectionView{

    if (!_allCollectionView) {
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
        flowLayout.minimumLineSpacing = 10;
     
        UICollectionView *collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, kWidth, kHeight - 44) collectionViewLayout:flowLayout];
        
        collectionView.backgroundColor = [UIColor blackColor];
        collectionView.delegate = self;
        collectionView.dataSource = self;
        _allCollectionView = collectionView;
    }
    return _allCollectionView;
}

-(NSMutableArray *)cellArr{

    if (!_cellArr) {
        _cellArr = [NSMutableArray arrayWithArray:@[@"DetailsCell",@"DetailsCell_1",@"DetailsCell_2",@"DetailsCell_3"]];
    }
    return _cellArr;
}

<<<<<<< HEAD
=======
-(NSMutableArray *)dataArray{
    
    if (!_dataArray) {
        _dataArray = [NSMutableArray new];
    }
    return _dataArray;
}

>>>>>>> 5bee59541ff07dbcbaa6fe419e6df24b39c5e23d

//添加底部按钮
-(void)addBottomBtn{

    UIButton *btn_1 = [UIButton buttonWithType:UIButtonTypeCustom];
    UIButton *btn_2 = [UIButton buttonWithType:UIButtonTypeCustom];
    UIButton *btn_3 = [UIButton buttonWithType:UIButtonTypeCustom];
    
    //设置颜色
    btn_1.backgroundColor = HWColor(0.95*255, 0.66*255, 0.21*255);
    btn_2.backgroundColor = HWColor(0.55*255, 0.6*255, 0.21*255);
    btn_3.backgroundColor = HWColor(0.32*255, 0.74*255, 0.54*255);
    //设置frame
    CGFloat width = [UIScreen mainScreen].bounds.size.width;
    CGFloat height = [UIScreen mainScreen].bounds.size.height - 44;
    btn_1.frame = CGRectMake(0, height, width*0.1, 44);
    btn_2.frame = CGRectMake(width*0.1,height,width*0.1,44);
    btn_3.frame = CGRectMake(width*0.2, height, width *0.8, 44);
    
    [btn_1 setTitle:@"收藏" forState:UIControlStateNormal];
    [btn_2 setTitle:@"客服" forState:UIControlStateNormal];
    [btn_3 setTitle:@"马上购物" forState:UIControlStateNormal];
    
    [btn_1 addTarget:self action:@selector(collection) forControlEvents:UIControlEventTouchUpInside];
    [btn_3 addTarget:self action:@selector(btnselete) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:btn_1];
    [self.view addSubview:btn_2];
    [self.view addSubview:btn_3];
    
   }



#pragma mark -- 按钮的回调方法

-(void)collection{

    NSLog(@"收藏点击成功");
    
    
    
    
    
    

}

-(void)btnselete{
    NSLog(@"购物点击成功");
    
    UIView *aView = [[UIView alloc]initWithFrame:CGRectMake(0, kHeight /2, [UIScreen mainScreen].bounds.size.width, kHeight/2+66)];
    aView.backgroundColor = [UIColor whiteColor];
    
    UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"shouhuodizhi"]];
    image.frame = CGRectMake(10, 10, 50, 50);
    [aView addSubview:image];
    
    
    UIButton *determineBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    determineBtn.frame = CGRectMake(0, kHeight/2+22, kWidth, 44);
    determineBtn.backgroundColor = HWColor(0.95*255, 0.66*255, 0.21*255);
    [determineBtn setTitle:@"确定" forState:UIControlStateNormal];
    
    [aView addSubview:determineBtn];
<<<<<<< HEAD
//        [self presentSemiView:aView];
=======

    
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(100 , 10, 200, 30)];
    
    titleLabel.text = @"【商城测试】iphone 6s";
    
    [aView addSubview:titleLabel];
    
    
>>>>>>> 5bee59541ff07dbcbaa6fe419e6df24b39c5e23d
    //添加背景图
    UIImageView * bgimgv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background_01"]];
    [self presentSemiView:aView withOptions:@{ KNSemiModalOptionKeys.backgroundView:bgimgv }];

}



<<<<<<< HEAD

#pragma mark -- 网络请求
- (void)fetchNetworkingWithURL:(NSString *)url parameter:(NSMutableDictionary*)parameter type:(NSInteger)type{

    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    [manager GET:url parameters:parameter progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"数据解析错误");
    }];
}



#pragma mark -- CollectionView的代理方法
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    
    return self.cellArr.count;
=======
#pragma mark -- CollectionView的代理方法
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    
    return 4;
>>>>>>> 5bee59541ff07dbcbaa6fe419e6df24b39c5e23d
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

    if (section == 3) {
        return 6;
<<<<<<< HEAD
=======
    }else if (section == 0){
     return 1;
>>>>>>> 5bee59541ff07dbcbaa6fe419e6df24b39c5e23d
    }
    return 1;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0) {
        DetailsCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"DetailsCell" forIndexPath:indexPath];
<<<<<<< HEAD
=======
        
            [cell setModel:self.model];
//        [cell setCellModel:self.dataArray[indexPath.row]];
>>>>>>> 5bee59541ff07dbcbaa6fe419e6df24b39c5e23d
        return cell;
    }else if(indexPath.section == 1){
        DetailsCell_1 *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"DetailsCell_1" forIndexPath:indexPath];

<<<<<<< HEAD
=======

>>>>>>> 5bee59541ff07dbcbaa6fe419e6df24b39c5e23d
        return cell;
    }else if(indexPath.section == 2){
        DetailsCell_2 *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"DetailsCell_2" forIndexPath:indexPath];

        [cell.detailsWeb loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.hao123.com"]]];
        return cell;
    }else{
    
        DetailsCell_3 *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"DetailsCell_3" forIndexPath:indexPath];
        return cell;
    }
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{


    if (indexPath.section == 0) {
        return CGSizeMake(kWidth, 100);
    }else if(indexPath.section == 2){
        return CGSizeMake(kWidth, 400);
    }else if(indexPath.section == 1){
        return CGSizeMake(kWidth, 80);
    }else{
        return CGSizeMake((kWidth -36)/3, 170);
    }
}

-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{

    if (section == 3) {
        return UIEdgeInsetsMake(10, 6, 10, 6);
    }else if(section == 0){
        return UIEdgeInsetsMake(64, 0, 7, 0);
    }
    return UIEdgeInsetsMake(0, 3, 6, 3);
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
